/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"8C47C0E9-41D6-45CB-940C-7AA1B92A0458",variableType:93}
 */
var fFecha = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C6FCD258-8AC1-4AD6-A140-97D36C91638B",variableType:4}
 */
var fProveedor = null;

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"6BDD6050-785E-4110-82C2-AD3F397806A8"}
 */
function buscar(event) {
	//var $query 	= 'SELECT precio_proveedor_id, producto_id FROM precios_proveedor_historico where proveedor_id = ? and fecha <= ?'
	var $query 	= 'SELECT precio_proveedor_id, producto_id FROM precios_proveedor_historico where proveedor_id = ? and fecha_desde >= ?'
	var $max 	= -1
	var $args 	= [fProveedor, fFecha]
	var $server	= 'infocom'
		
	var $ds		= databaseManager.getDataSetByQuery($server,$query,$args,$max)
	
	var $prod_ant = $ds.getValue(1,2)
	var i = 2
	while (i <= $ds.getMaxRowIndex())
	{
		$ds.rowIndex = i
		if ($ds[2] == $prod_ant)
			$ds.removeRow(i)
		else
		{
			$prod_ant = $ds[2]
			i++
		}
	}
	$ds.removeColumn(2)
	controller.loadRecords($ds)
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"BB488585-5803-4E2C-86C1-2CB47C4776EE"}
 */
function proveedorNull(event) {
	fProveedor = null
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"D44FF72A-A82B-4FA0-8CFF-1B2706A26D3C"}
 */
function fechasNull(event) {
	fFecha = null
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"912B546F-4B57-4FC4-863B-B620189DBA20"}
 */
function onShow(firstShow, event) {
	databaseManager.revertEditedRecords()
	databaseManager.setAutoSave(true)
	
	controller.loadRecords(null)
}
